package com.shinbada.core.excel.convert;

import com.shinbada.excel.convert.ReadConverter;
import com.shinbada.excel.convert.WriteConverter;
import com.shinbada.excel.exception.ExcelKitReadConverterException;
import com.shinbada.excel.exception.ExcelKitWriteConverterException;
import com.shinbada.modules.sys.utils.DictUtils;

/**
 * @author initcap
 * @date Created in 2020/11/11 10:30.
 */
public class DictConverter implements ReadConverter, WriteConverter {

    private String dictType;

    @Override
    public void init(Object... value) {
        this.dictType = (String) value[0];
    }

    @Override
    public Object readConvert(Object value) throws ExcelKitReadConverterException {
        return DictUtils.getDictValue((String) value, dictType, "");
    }

    @Override
    public String writeConvert(Object value) throws ExcelKitWriteConverterException {
        return DictUtils.getDictLabel((String) value, dictType, "");
    }
}
